1146B - Hate "A" - CodeForces Solution


implementation strings *1100

Please click on ads to support us..

Python Code:

t = str(input())
s = t.replace('a','')
s_ = s[int(len(s)/2):] 
s = s[:int(len(s)/2)] 
if(s==s_):
  s = t[0:len(t)-len(s_)]
  if t == s+s_:
    print(s)
  else:
    print(":(")
else:
  print(":(")
	     	 	 				   		  	 		   	 	

C++ Code:

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	int num=0,fl=0,fls=0;
	bool flag = 1;
	string str;
	cin >> str;
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == 'a')
		{
			num++;
			fl = i;
		}
	}
	fls = (str.size() + num) / 2;

	if (fls < fl)flag == 0;
	if (str.size() - num & 1)flag = 0;
	int l = 0, r = fls;
	//cout << "ll rr" << l << "///" << r << endl;
	while (r <str.size())
	{
		if (str[l] == 'a')
		{
			l++;
			continue;
		}

		if (str[l] != str[r])
		{
			flag = 0;
			//cout << "l=" << l<<"r="<<r<<"str[l]="<<str[l]<<"str[r]="<<str[r]<<endl;
			break;
		}
		l++;
		r++;

		
	}

	if (flag)
	{
		for (int i = 0; i < fls; i++)
			cout << str[i];
	}
	else cout << ":(" << endl;
}
	  		 	  	    		  					 	   			


Comments

Submit
0 Comments
More Questions

343B - Alternating Current
758B - Blown Garland
1681B - Card Trick
1592A - Gamer Hemose
493D - Vasya and Chess
1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts